<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>流失客户原因</title>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css"/>
    <style>
        .layui-form{width: 80%;margin: 0 auto;}
        .layui-input-block{width: 70%;margin-top: 10px}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="editForm">
    <div class="layui-form-item">
        <label class="layui-form-label">客户编号</label>
        <div class="layui-input-block">
            <input type="text" name="cusId" id="cusId" lay-verify="required" autocomplete="off" class="layui-input" readonly unselectable="on"
                   style="cursor: not-allowed">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户姓名</label>
        <div class="layui-input-block">
            <input type="text" name="cusName" id="cusName" lay-verify="required" autocomplete="off" class="layui-input"readonly unselectable="on"
                   style="cursor: not-allowed">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户经理</label>
        <div class="layui-input-block">
            <input type="text" name="cusManger" id="cusManger" lay-verify="required" autocomplete="off" class="layui-input" readonly unselectable="on"
                   style="cursor: not-allowed">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最后下单</label>
        <div class="layui-input-block">
            <input type="date" name="lastOrderTime" id="lastOrderTime" lay-verify="required" placeholder="请输入最后下单时间" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">流失原因</label>
        <div class="layui-input-block">
            <input type="textarea" rows="10" cols="20" name="lossReason" id="lossReason" placeholder="请输入流失原因" autocomplete="off" class="layui-textarea">
        </div>
    </div>


    <div class="layui-form-item" style="width: 100%;margin-top: 30px;">
        <div class="layui-input-block" style="width: 80%;margin: 0 auto;text-align: center;">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="putIn">提交</button>
            <!--            <button type="submit" class="layui-btn" lay-submit="" lay-filter="update">保存修改</button>-->
        </div>
        <!--        把id输入框设为隐藏-->
        <div class="layui-form-item" >
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id" lay-verify="title" autocomplete="off" placeholder="请输入id" class="layui-input">
            </div>
        </div>
    </div>
</form>

<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="../../js/jquery3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/area.js" type="text/javascript"></script>
<script src="../../js/select.js" type="text/javascript"></script>
<script>
    layui.use(['form'], function(){
        var form = layui.form;
        //判断是新增还是修改
        var myUrl="";
        if ($('#id').val() == ""){
            myUrl="http://localhost:8080/crm/customerLoss/save";
        }else{
            myUrl="http://localhost:8080/crm/customerLoss/update";
        }
        //监听添加
        form.on('submit(putIn)', function(data){
            layer.alert("恭喜你，添加成功！",{
                title: 'crm提示'
            })
            //向后台发送ajax请求
            $.ajax({
                //编写json格式，设置属性和值
                url:myUrl,
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(data.field),
                dataType:"json",
                type:"post",
                async:false,
                success:function (data){
                },
                end:parent.location.reload()
            })
            return false;
        });
        //表单验证
        form.verify({
            username: function(value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '姓名不能为空且不能含有特殊字符';
                }
            }
            ,tel:function (value) {
                if (!new RegExp("^[1][0-9]{10}$").test(value)){
                    return '手机号只能是11位数字';
                }
            }
        })

        $("#cusId").click(function () {
            layer.msg("不可修改");
        })
    });
    //地址
    function jg(){
        alert($("#province").val()+$("#city").val()+$("#district").val());
    }

</script>
</body>
</html>